package com.atguigu.blog.article.controller;

import com.atguigu.blog.article.entity.Article;
import com.atguigu.blog.article.service.ArticleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("article")
public class ArticleController {

@Autowired
private ArticleService articleService;

    @GetMapping("user/list")
    public List<Article> findAllArticle(@RequestParam Long userId){
        LambdaQueryWrapper<Article> articleLambdaQueryWrapper = new LambdaQueryWrapper<>();
        articleLambdaQueryWrapper.eq(Article::getUserId,userId);
        List<Article> articleList = articleService.list(articleLambdaQueryWrapper);
        return articleList;
    }

    @GetMapping("{articleId}")
    public Article findArticleById(@PathVariable("articleId") Long id){
        Article  article = articleService.doFindArticleById(id);
        return article;
    }
}
